home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE6 / PD / PDF / pdf / c++ / main < prev    next >
Text File  |  2003-02-24  |  7KB  |  250 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //   Copyright (c) 2002, Colin Granville
  4. //
  5. //   All rights reserved.
  6. //
  7. //   Redistribution and use in source and binary forms, with or
  8. //   without modification, are permitted provided that the following 
  9. //   conditions are met:
  10. //
  11. //      * Redistributions of source code must retain the above copyright 
  12. //        notice, this list of conditions and the following disclaimer.
  13. //
  14. //      * Redistributions in binary form must reproduce the above 
  15. //        copyright notice, this list of conditions and the following 
  16. //        disclaimer in the documentation and/or other materials 
  17. //        provided with the distribution.
  18. //
  19. //      * The name Colin Granville may not be used to endorse or promote 
  20. //        products derived from this software without specific prior 
  21. //        written permission.
  22. //
  23. //   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  24. //   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  25. //   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  26. //   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  27. //   COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
  28. //   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  29. //   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  30. //   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
  31. //   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  32. //   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  33. //   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
  34. //   OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //--------------------------------------------------------------------------
  37.  
  38. #include "GuiWindow.h"
  39. #include "GuiTargets.h"
  40. #include "GuiTask.h"
  41. #include "Document.h"
  42. #include "DocView.h"
  43. #include "Flex.h"
  44. #include "fstream.h"
  45. #include <stdlib.h>
  46. #include <stdarg.h>
  47. #include "gtypes.h"
  48. #include "Node.h"
  49. #include "error.h"
  50. #include "globalparams.h"
  51. #include "strstream.h"
  52. #include "UserEvents.h"
  53. #include "GuiIconbar.h"
  54. #include "GuiFlexGlobal.h"
  55.  
  56. // first part is the xpdf version number
  57. #ifndef __APCS_32
  58. #define  VERSION "2.01.1.11"
  59. #else
  60. #define  VERSION "2.01.1.11 32bit"
  61. #endif
  62.  
  63. class Application : public Node
  64. {
  65.   public:
  66.     Application(int argc,char** argv);
  67.     virtual Node* removeChild(Node*);
  68.     virtual bool  hasChildNodes()                {return 1;}
  69.     DECLARE_RTTI_DERIVED(Application,Node);
  70.  
  71.   private:
  72.     GuiIconbar iconbar;
  73.  
  74.     virtual ~Application() {}
  75.  
  76.     bool createDocument(const char* filename);
  77.  
  78.     GUI_DECLARE_EVENT_TARGETS(Application);
  79.  
  80.     GuiToolboxTarget userQuitTarget;
  81.     Claim userQuit(GuiToolboxEvent&,const GuiIdBlock&);
  82.  
  83.     GuiToolboxTarget showHelpTarget;
  84.     Claim showHelp(GuiToolboxEvent&,const GuiIdBlock&);
  85.  
  86.  
  87.     GuiMessageTarget messageQuitTarget;
  88.     Claim messageQuit(GuiWimpMessage&);
  89.  
  90.     GuiMessageTarget dataOpenTarget;
  91.     Claim dataOpen(GuiWimpMessage&);
  92.  
  93.     GuiMessageTarget dataLoadTarget;
  94.     Claim dataLoad(GuiWimpMessage&);
  95. };
  96.  
  97. //*************************************************************************
  98.  
  99. Application::Application(int argc,char** argv)
  100.   : iconbar("Iconbar"),
  101.     userQuitTarget(0,User_Quit,this,Application::userQuit),
  102.     showHelpTarget(0,User_ShowHelp,this,Application::showHelp),
  103.     messageQuitTarget(GuiWimp_MQuit,this,Application::messageQuit),
  104.     dataOpenTarget(GuiWimp_MDataOpen,this,Application::dataOpen),
  105.     dataLoadTarget(GuiWimp_MDataLoad,this,Application::dataLoad)
  106. {
  107.   char* file_name=0;
  108.   int i;
  109.   for (i=1;i<argc;i++)
  110.   {
  111.     file_name=argv[i];
  112.   }
  113.  
  114.   if (file_name==0)  iconbar.show();
  115.  
  116.   if (!createDocument(file_name) && !iconbar.isShowing()) exit(EXIT_SUCCESS);
  117. }
  118.  
  119. //*************************************************************************
  120.  
  121. bool Application::createDocument(const char* filename)
  122. {
  123.    DocViewChoices choices;
  124.    return makeDocView(makeDocument(*this,filename),choices); 
  125. }
  126.  
  127. //*************************************************************************
  128.  
  129. Node* Application::removeChild(Node* n)
  130. {
  131.   Node::removeChild(n);
  132.   if (getFirstChild()==0 && !iconbar.isShowing())
  133.   {
  134.     delete this;
  135.     exit(EXIT_SUCCESS);
  136.   }
  137.   return n;
  138. }
  139.  
  140. //*************************************************************************
  141.  
  142. Claim Application::userQuit(GuiToolboxEvent&,const GuiIdBlock&)
  143. {
  144.   delete this;
  145.   exit(EXIT_SUCCESS);
  146.   return CLAIM;
  147. }
  148.  
  149. //*************************************************************************
  150.  
  151. Claim Application::showHelp(GuiToolboxEvent&,const GuiIdBlock&)
  152. {
  153.   _swix(OS_CLI,_IN(0),"filer_run <pdf$dir>.!help");
  154.   return CLAIM;
  155. }
  156.  
  157. //*************************************************************************
  158.  
  159. Claim Application::messageQuit(GuiWimpMessage&)
  160. {
  161.   delete this;
  162.   exit(EXIT_SUCCESS);
  163.   return CLAIM;
  164. }
  165.  
  166. //*************************************************************************
  167.  
  168. Claim Application::dataOpen(GuiWimpMessage& mess)
  169. {
  170.   bool claim=0;
  171.   switch (mess.data.dataOpen.fileType)
  172.   {
  173.     case 0xadf: mess.acknowledge();
  174.                 createDocument(mess.data.dataOpen.pathName);
  175.                 return CLAIM;
  176.   }
  177.   return DONT_CLAIM;
  178. }
  179.  
  180. //*************************************************************************
  181.  
  182. Claim Application::dataLoad(GuiWimpMessage& mess)
  183. {
  184.   if (mess.data.dataLoad.destination.windowHandle!=-2) return DONT_CLAIM;
  185.  
  186.   if (createDocument(mess.data.dataLoad.leafName))
  187.   {
  188.       mess.reply(GuiWimp_MDataLoadAck);
  189.   }
  190.   return CLAIM;
  191. }
  192.  
  193. //*************************************************************************
  194. //*************************************************************************
  195. //*************************************************************************
  196. class ProgramInfo
  197. {
  198.   public:
  199.     ProgramInfo();
  200.     ~ProgramInfo();
  201.   private:
  202.     GuiWindow       info;
  203.     GuiDisplayField version;
  204.  
  205.     GUI_DECLARE_EVENT_TARGETS(ProgramInfo);
  206.  
  207.     GuiToolboxTarget atbs_target;
  208.     Claim atbs(GuiToolboxEvent&,const GuiIdBlock&);
  209. };
  210.  
  211. ProgramInfo::ProgramInfo()
  212.   : info("ProgInfo"),
  213.     version(info,9),
  214.     atbs_target(&info,0x82880,this,ProgramInfo::atbs)
  215. {
  216. }
  217. //*****************************************************************
  218.  
  219. ProgramInfo::~ProgramInfo()
  220. {
  221. }
  222.  
  223. //*****************************************************************
  224.  
  225. Claim ProgramInfo::atbs(GuiToolboxEvent&,const GuiIdBlock&)
  226. {
  227.   char buf[64];
  228.   ostrstream out(buf,sizeof(buf));
  229.   out << VERSION << " (";
  230.   if (__DATE__[4] != ' ') out <<__DATE__[4];
  231.   out << __DATE__[5] << ' ';
  232.   out.write(__DATE__,3);
  233.   out <<' ' << (__DATE__+7) << ')';
  234.   version.setValue(out.str());
  235.   return CLAIM;
  236. }
  237.  
  238. //*************************************************************************
  239. //*************************************************************************
  240. //*************************************************************************
  241. int main(int argc,char** argv)
  242.   globalParams = new GlobalParams("");
  243.   globalParams->setErrQuiet(1);
  244.   guiTaskInitialise("<PDF$Dir>");
  245.   new Application(argc,argv);
  246.   ProgramInfo info;
  247.   for (;;)  GuiRegister::poll();
  248. }
  249.